<?php
class AdminProvince extends CActiveRecord{

    public static function model($className = __CLASS__) {
        return parent::model ( $className );
    }

    // dat luat cho model
    public function rules(){}         

    // goi den bang can ket noi   
    public function tableName() {                  
        return 'province';
    }

    // nhan cac thuong tinh 
    public function attributeLabels(){}

    public function getRowById($id){
        $id = intval($id);
        $row = array();

        $sql = "SELECT id,name,region FROM province WHERE id=".$id;
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $row = $command->queryRow();

        return $row;
    }

    public function getRowsByRegion($id_region){
        $id_region = intval($id_region);

        $rows = array();

        $sql = "SELECT id,name FROM province WHERE region=".$id_region;
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $rows = $command->queryAll();

        return $rows;
    } 
    public function getRowsByDateAndRegion($id_region,$day){
        $day = intval($day);
        $id_region = intval($id_region);

        $rows = array();
        $sql = "SELECT id,name FROM province WHERE region=".$id_region." AND thu".$day." = 1";   
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $rows = $command->queryAll();

        return $rows;
    }   

    public function getRowsByDay($day){
        $day = intval($day);

        $rows = array();

        $sql = "SELECT id,name FROM province WHERE thu".$day." = 1";
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $rows = $command->queryAll();

        return $rows;
    }

    public function getAllRows(){
        //$id_region = intval($id_region);

        $rows = array();

        $sql = "SELECT id,name FROM province";
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $rows = $command->queryAll();

        return $rows;
    } 
}
